package com.standardoperationapp.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.standardoperationapp.R;
import com.standardoperationapp.bean.OperationPlanBean;
import com.standardoperationapp.global.DateUtils;
import com.standardoperationapp.global.PlanListItem;

import java.util.List;

/**
 * 作业计划adapter
 */
public class PlanListAdapter  extends BaseAdapter {

    //	private List<MessageItem>nlist =new ArrayList<MessageItem>();
	/*private int resourceId;
	public MsgAdapter(Context context, int resource,List<MessageItem> objects) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		resourceId=resource;
	}*/
    private List<OperationPlanBean.DataBean> list;
    private LayoutInflater mInflater;

    public PlanListAdapter(Context context, List<OperationPlanBean.DataBean> list1) {
        list = list1;
        mInflater = LayoutInflater.from(context);
    }



    public int getCount() {
        return list.size();
    }

    public Object getItem(int position) {
        return list.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public int getItemViewType(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        OperationPlanBean.DataBean item = list.get(position);
        ViewHolder viewHolder = null;

        if(convertView == null){
            convertView = mInflater.inflate(R.layout.planlist_item, null);
            viewHolder=new ViewHolder(
                    (View) convertView.findViewById(R.id.planlist_layout),
                    (TextView) convertView.findViewById(R.id.planlist_title),
                    (TextView) convertView.findViewById(R.id.planlist_position2),
                    (TextView) convertView.findViewById(R.id.planlist_time2),
                    (TextView) convertView.findViewById(R.id.planlist_info2)
            );
            convertView.setTag(viewHolder);
        }
        else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        String date = DateUtils.formatToString(item.getStartTime(), "yyyy-MM-dd");
        viewHolder.titleTxt.setText(date + "  " + item.getWorkAreaName());
        viewHolder.positionTxt.setText(item.getWorkLocation());
        viewHolder.timeTxt.setText(item.getStartTime());

        String projectNames = item.getProjectNames().replace("," ,"\n");
        viewHolder.infoTxt.setText(projectNames);

//        {
//            viewHolder.child.setBackgroundResource(R.drawable.msgbox_send);
//            viewHolder.msgTextView.setText(item.getComItem());
//        }
//        else
//        {
//            viewHolder.child.setBackgroundResource(R.drawable.msgbox_rec);
//            viewHolder.msgTextView.setText(item.getComItem());
//        }


        return convertView;
    }
    class ViewHolder
    {
        protected TextView titleTxt,positionTxt,timeTxt,infoTxt;
        protected View child;


        public ViewHolder(View child, TextView title,TextView position,TextView time,TextView info){
            this.child = child;
            this.titleTxt = title;
            this.positionTxt=position;
            this.timeTxt = time;
            this.infoTxt = info;


        }
    }
}
